package org.firebug.spring.boot.jackson.controller;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import lombok.experimental.Accessors;
import org.firebug.spring.boot.jackson.serializer.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
@RequestMapping(value = "/jackson")
public class JacksonController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @RequestMapping(value = "/query", method = RequestMethod.GET)
    public User save() {
        User user = new User();
        return user;
    }

    @Data
    @Accessors(chain = true)
    static class User {
        private Long id = 1L;
        @JsonSerialize(using = MobileHiddenSerializer.class)
        private String mobile = "134 8233 6363";

        @JsonSerialize(using = Percentage0Serializer.class)
        private BigDecimal percent0 = new BigDecimal("0.123456");
        @JsonSerialize(using = Percentage1Serializer.class)
        private BigDecimal percent1 = new BigDecimal("0.123456");
        @JsonSerialize(using = Percentage2Serializer.class)
        private BigDecimal percent2 = new BigDecimal("0.123456");
        @JsonSerialize(using = Permillage0Serializer.class)
        private BigDecimal permillage0 = new BigDecimal("0.123456");
        @JsonSerialize(using = Permillage1Serializer.class)
        private BigDecimal permillage1 = new BigDecimal("0.123456");
        @JsonSerialize(using = Permillage2Serializer.class)
        private BigDecimal permillage2 = new BigDecimal("0.123456");

        @JsonSerialize(using = AmountToYuan42Serializer.class)
        private BigDecimal yuan = new BigDecimal("12345.6789");
        @JsonSerialize(using = AmountToWan42Serializer.class)
        private BigDecimal wan = new BigDecimal("12345.6789");
        @JsonSerialize(using = AmountToUpperSerializer.class)
        private BigDecimal rmb = new BigDecimal("12345.67");
    }
}
